package com.toune.movie.mvp.adapter;

import android.content.Intent;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.RelativeLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.toune.movie.R;
import com.toune.movie.mvp.activity.ComicVideoActivity;
import com.toune.movie.mvp.activity.MovieVideoActivity;
import com.toune.movie.mvp.activity.TvVideoActivity;
import com.toune.movie.mvp.activity.VarietyDetailActivity;
import com.toune.movie.mvp.activity.VarietyVideoActivity;
import com.toune.movie.vo.MovieContentVo;

import java.util.List;

public class AdapterMovieContent extends BaseQuickAdapter<MovieContentVo, BaseViewHolder> {
    public AdapterMovieContent(int layoutResId, @Nullable List<MovieContentVo> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, final MovieContentVo item) {
        helper.setText(R.id.title_tv, item.getTitle());
        RelativeLayout relativeLayout = helper.getView(R.id.more_rl);
        relativeLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                switch (item.getTag()){
                    case 0:
                        intent.setClass(mContext, MovieVideoActivity.class);
                        break;
                    case 1:
                        intent.setClass(mContext, TvVideoActivity.class);
                        break;
                    case 2:
                        intent.setClass(mContext, VarietyVideoActivity.class);
                        break;
                    case 3:
                        intent.setClass(mContext, ComicVideoActivity.class);
                        break;
                }
                intent.putExtra("url", item.getUrl());
                mContext.startActivity(intent);
            }
        });
        RecyclerView recyclerView = helper.getView(R.id.rclview);
        AdapterVariety adapterVariety5 = new AdapterVariety(R.layout.adapter_variety, item.getDataBeans());
        recyclerView.setLayoutManager(new GridLayoutManager(mContext, 3));
        recyclerView.setAdapter(adapterVariety5);
        adapterVariety5.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Intent intent = new Intent(mContext, VarietyDetailActivity.class);
                intent.putExtra("url", item.getDataBeans().get(position).getDetailUrl());
                intent.putExtra("title", item.getDataBeans().get(position).getTitle());
                intent.putExtra("tag", item.getTag());//0表示是电影，1表示其他
                intent.putExtra("imgUrl", item.getDataBeans().get(position).getImagSrc());
                mContext.startActivity(intent);
            }
        });
    }
}
